home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJLSR106.ARJ / UNGETC.C < prev    next >
C/C++ Source or Header  |  1992-03-02  |  692b  |  31 lines

  1. /* This is file UNGETC.C */
  2. /* This file may have been modified by DJ Delorie (Jan 1991).  If so,
  3. ** these modifications are Coyright (C) 1991 DJ Delorie, 24 Kirsten Ave,
  4. ** Rochester NH, 03867-2954, USA.
  5. */
  6.  
  7. #if defined(LIBC_SCCS) && !defined(lint)
  8. static char sccsid[] = "@(#)ungetc.c    5.3 (Berkeley) 3/26/86";
  9. #endif LIBC_SCCS and not lint
  10.  
  11. #include <stdio.h>
  12.  
  13. ungetc(c, iop)
  14.     register FILE *iop;
  15. {
  16.     if (c == EOF || (iop->_flag & (_IOREAD|_IORW)) == 0 ||
  17.         iop->_ptr == NULL || iop->_base == NULL)
  18.         return (EOF);
  19.  
  20.     if (iop->_ptr == iop->_base)
  21.         if (iop->_cnt == 0)
  22.             iop->_ptr++;
  23.         else
  24.             return (EOF);
  25.  
  26.     iop->_cnt++;
  27.     *--iop->_ptr = c;
  28.  
  29.     return (c);
  30. }
  31.